<?php
/* 提醒文本相关操作控制器 */

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Validator;

class ReminderController extends HomeController
{
    //获取列表
    public function update(Request $request)
    {
        try {
            // 分页参数
            $id = $request->input('id');

            //接受参数并组装成数组
            $data = [];
            $data['content'] = $request->input('content');

            //修改数据到数据表
            DB::table('reminder_text')->where('id', $id)->update($data);

            return response()->json([
                'code' => HTTP_OK,
                'message' => HTTP_OK_MESSAGE,
            ]);
        } catch (\Exception $e) {
            // 记录错误日志
            Log::error('修改提醒文本失败: ' . $e->getMessage());
            return response()->json([
                'code' => HTTP_ERROR,
                'message' => '修改提醒文本失败',
                'data' => null
            ]);
        }
    }

    

    //详情
    public function detail(Request $request)
    {
        try {
            //接受参数
            $type = $request->input('type');
            if (!$type) {
                return response()->json(['code' => HTTP_ERROR,'message' => HTTP_MISSING_PARAMETER_MESSAGE,'data' => null]);
            }
            //根据id查询详情
            $data = DB::table('reminder_text')->where('type', $type)->first();

            return response()->json(['code' => HTTP_OK,'message' => HTTP_OK_MESSAGE,'data' => $data]);
        } catch (\Exception $e) {
            // 记录错误日志
            Log::error('获取提醒文本详情失败: ' . $e->getMessage());
            return response()->json([
                'code' => HTTP_ERROR,
                'message' => '获取提醒文本详情失败',
                'data' => null
            ]);
        }
    }

}
